# 元组是不可变的数据类型，所以不可以新增、修改、删除
# 元组支持索引访问
a_tuple = (10,20,30,"郝健车工","郝健脑工",[10,20,30],1.1)
# 从左往右   0  1  2    3           4         5       6
# 从右往左   -7 -6 -5   -4         -3         -2       -1
# 我想通过索引访问拿到20
# print(a_tuple[5][1]) # 20
# 元组支持切片访问
# print(a_tuple[3:5])             # "郝健车工","郝健脑工"
# 元组支持链接操作
b_tuple = (10,20,30)
c_tuple = a_tuple+b_tuple
# print(c_tuple)
# 元组支持*
# d_tuple = b_tuple*3
# print(d_tuple)[飞吻]
# 可以创建空元组
"""e_tuple = tuple()
print(e_tuple)"""
# 创建仅有一个成员的元组
"""f_tuple = (1)
print(f_tuple)
print(type(f_tuple)) # <class 'int'>"""
"""g_tuple = (1,)
print(g_tuple) # 这样才是正确的
print(type(g_tuple)) # <class 'tuple'>"""
# 使用tuple创建元组
"""o_tuple = tuple(range(3))
print(o_tuple)"""
# 元组内容不可以进行修改
"""a_tuple[0] = "好简称"
print(a_tuple)"""
# 获取元素的下标和计数
nums = (99,10,20,30,40,10,55)
"""print(nums.index(10)) # 获取元素值所在的索引位置
print(nums.count(10)) # 获取元组10的数量"""
# 元组排序的方法
"""print(sorted(nums)) # 原地排序，原来的元组不会受到影响
print(nums) # (99,10,20,30,40,10,55)
print(sorted(nums,reverse=True)) # 降序返回"""
# 访问元组最大值
# print(f"元组的最大值是：{max(nums)}") # 99
# 元组最小值
# print(f"元组最小值是：{min(nums)}") # 10
# 元组的和
# print(f"元组的和是：{sum(nums)}") # 99+10+20+30+40+10+55
# 获取元组的长度
# print(f"{nums}的长度是{len(nums)}")
# zip对象
a = [10,20,30]
b = [40,50,60]
c = [60,80,90]
e = zip(a,b,c)
# print(e) # 地址值 <zip object at 0x000002AB9BA28640>
# print(list(e)) # [(10, 40, 60), (20, 50, 80), (30, 60, 90)]

# 生成器推导式创建元组
s = (i*2 for i in range(5))
print(s)  # 直接访问会是地址值
print(tuple(s)) # (0, 2, 4, 6, 8)
print(list(s)) # []
# 0,1,2,3,4
#   (0*2,1*2,2*2,3*2,4*2)
# s 输出的结果：(0,2,4,6,8)

"""
元组的总结：
1、元组是不可变的数据结构
对元组进行增、删、改必然会报错
2、创建一个空元组
n = tuple()
2.1、创建一个仅有一个的元组
p = (1,)
3、元组支持索引访问、切片访问
[索引访问]
num_tuple = (10,20,30)
print(num_tuple[0]) # 10
[切片访问]
new_tuple = num_tuple[1:3]
print(new_tuple) # 拿出来的值就是：(20,30)
4、元组中如果包含了可变的数据类型，可以改
nums_tuple = (10,20,30,[10,20,30])
nums_tuple[3][1] = "郝健成"
print(nums_tuple) # (10,20,30,[10,"郝健成",30])
"""
"""nums_tuple = (10,20,30,(10,20,30))
nums_tuple[3][1] = "郝健成"
print(nums_tuple) # (10,20,30,[10,"郝健成",30])"""













